package org.panda.tcmoc.view;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.EditorPart;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Text;
import org.panda.tcmoc.domain.SpProduct;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.core.databinding.beans.BeanProperties;
import org.eclipse.swt.widgets.DateTime;

public class SpDetailEditorPart extends EditorPart {
	private DataBindingContext m_bindingContext;

	public static final String ID = "org.panda.tcmoc.view.SpDetailEditorPart"; //$NON-NLS-1$
	private SpProduct _viewSp;

	private Text text_dealTicketNo;
	private Text text_cnyAmount;
	private Text text_pkSeqNo;
	private Text text_branchNo;
	private Text text_gtdNo;
	private Text text_productName;
	private Text text_productCode;

	String strText = "";
	private Text text_ccy;
	private Text text_acType;
	private Text text_nominalPrinAc;
	private Text text_counterPartyName;
	private Text text_counterPartyCode;
	private Text text_opType;
	private Text text_counterPartyType;
	private Text text_agType;
	private Text text_marketValue;
	private Text text_type;
	private Text text_status;
	private DateTime dateTime_beginDate;
	private DateTime dateTime_endDate;
	private Text text_1;
	private Text text_2;
	private Text text_gtd;

	public SpDetailEditorPart() {
	}

	public void setText(String text) {
		this.text_dealTicketNo.setText(text);
	}

	/**
	 * Create contents of the editor part.
	 * 
	 * @param parent
	 */
	@Override
	public void createPartControl(Composite parent) {
		Composite container = new Composite(parent, SWT.NONE);

		TabFolder tabFolder = new TabFolder(container, SWT.NONE);
		tabFolder.setBounds(0, 0, 684, 510);

		TabItem tbtmBasicInfo_1 = new TabItem(tabFolder, SWT.NONE);
		tbtmBasicInfo_1.setText("Basic Info");

		Composite composite = new Composite(tabFolder, SWT.NONE);
		tbtmBasicInfo_1.setControl(composite);

		Label lblDealTicketNo = new Label(composite, SWT.NONE);
		lblDealTicketNo.setLocation(10, 29);
		lblDealTicketNo.setSize(84, 12);
		lblDealTicketNo.setText("Deal Ticket No");

		text_dealTicketNo = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
		text_dealTicketNo.setBounds(114, 26, 142, 18);

		text_dealTicketNo.setText(strText);

		Label lblCnyAmount = new Label(composite, SWT.NONE);
		lblCnyAmount.setText("CNY Amount");
		lblCnyAmount.setBounds(321, 32, 84, 12);

		text_cnyAmount = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
		text_cnyAmount.setBounds(411, 26, 177, 18);

		Label lblPk = new Label(composite, SWT.NONE);
		lblPk.setText("PK\u987A\u5E8F\u53F7");
		lblPk.setBounds(10, 65, 84, 12);

		text_pkSeqNo = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
		text_pkSeqNo.setBounds(114, 62, 142, 18);

		Label label = new Label(composite, SWT.NONE);
		label.setText("\u5206\u884C\u53F7");
		label.setBounds(10, 102, 84, 12);

		text_branchNo = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
		text_branchNo.setBounds(114, 99, 142, 18);

		Label label_1 = new Label(composite, SWT.NONE);
		label_1.setText("\u5173\u8054\u53F7");
		label_1.setBounds(321, 102, 84, 12);

		text_gtdNo = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
		text_gtdNo.setBounds(411, 99, 177, 18);

		Label label_2 = new Label(composite, SWT.NONE);
		label_2.setText("\u4EA7\u54C1\u540D\u79F0");
		label_2.setBounds(10, 137, 84, 12);

		text_productName = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
		text_productName.setBounds(114, 134, 142, 18);

		Label label_3 = new Label(composite, SWT.NONE);
		label_3.setText("\u4EA7\u54C1\u540D\u79F0");
		label_3.setBounds(321, 137, 84, 12);

		text_productCode = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
		text_productCode.setBounds(411, 134, 177, 18);

		text_ccy = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
		text_ccy.setBounds(114, 172, 142, 18);

		Label label_4 = new Label(composite, SWT.NONE);
		label_4.setText("\u5E01\u79CD");
		label_4.setBounds(10, 175, 84, 12);

		Label label_5 = new Label(composite, SWT.NONE);
		label_5.setText("\u540D\u4E49\u672C\u91D1");
		label_5.setBounds(321, 175, 84, 12);

		Label label_6 = new Label(composite, SWT.NONE);
		label_6.setText("\u8D26\u6237\u7C7B\u578B");
		label_6.setBounds(10, 207, 84, 12);

		Label label_7 = new Label(composite, SWT.NONE);
		label_7.setText("\u4EA4\u6613\u5BF9\u624B\u540D\u79F0");
		label_7.setBounds(10, 241, 84, 12);

		Label label_8 = new Label(composite, SWT.NONE);
		label_8.setText("\u4EA4\u6613\u5BF9\u624B\u7C7B\u578B");
		label_8.setBounds(321, 241, 84, 12);

		Label label_9 = new Label(composite, SWT.NONE);
		label_9.setText("\u4EA4\u6613\u5BF9\u624B\u4EE3\u7801");
		label_9.setBounds(10, 274, 84, 12);

		Label lblOperationType = new Label(composite, SWT.NONE);
		lblOperationType.setText("Operation Type");
		lblOperationType.setBounds(10, 307, 84, 12);

		Label lblAgreeementtype = new Label(composite, SWT.NONE);
		lblAgreeementtype.setText("AgreementType");
		lblAgreeementtype.setBounds(321, 307, 84, 12);

		Label lblMarketValue = new Label(composite, SWT.NONE);
		lblMarketValue.setText("Market Value");
		lblMarketValue.setBounds(10, 366, 84, 12);

		Label label_10 = new Label(composite, SWT.NONE);
		label_10.setText("\u8D77\u59CB\u65E5\u671F");
		label_10.setBounds(10, 338, 84, 12);

		Label label_11 = new Label(composite, SWT.NONE);
		label_11.setText("\u7ED3\u675F\u65E5\u671F");
		label_11.setBounds(321, 338, 84, 12);

		text_nominalPrinAc = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
		text_nominalPrinAc.setBounds(411, 172, 177, 18);

		text_acType = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
		text_acType.setBounds(114, 201, 142, 18);

		text_counterPartyName = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
		text_counterPartyName.setBounds(114, 235, 142, 18);

		text_counterPartyType = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
		text_counterPartyType.setBounds(411, 235, 177, 18);

		text_counterPartyCode = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
		text_counterPartyCode.setBounds(114, 268, 142, 18);

		text_opType = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
		text_opType.setBounds(114, 301, 142, 18);

		text_agType = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
		text_agType.setBounds(411, 301, 177, 18);

		text_marketValue = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
		text_marketValue.setBounds(114, 366, 142, 18);

		dateTime_beginDate = new DateTime(composite, SWT.BORDER);
		dateTime_beginDate.setEnabled(false);
		dateTime_beginDate.setBounds(114, 329, 142, 21);

		dateTime_endDate = new DateTime(composite, SWT.BORDER);
		dateTime_endDate.setEnabled(false);
		dateTime_endDate.setBounds(411, 329, 177, 21);

		Label lblType = new Label(composite, SWT.NONE);
		lblType.setText("Type");
		lblType.setBounds(10, 393, 84, 12);

		text_type = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
		text_type.setBounds(114, 390, 142, 18);

		text_status = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
		text_status.setBounds(411, 390, 177, 18);

		Label lblStatus = new Label(composite, SWT.NONE);
		lblStatus.setText("Status");
		lblStatus.setBounds(321, 393, 84, 12);
		
		Label lblVersion = new Label(composite, SWT.NONE);
		lblVersion.setText("Version");
		lblVersion.setBounds(10, 423, 84, 12);
		
		Label lblSubversio = new Label(composite, SWT.NONE);
		lblSubversio.setText("SubVersion");
		lblSubversio.setBounds(321, 423, 84, 12);
		
		text_1 = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
		text_1.setBounds(114, 420, 142, 18);
		
		text_2 = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
		text_2.setBounds(411, 420, 142, 18);
		
		Label lblGtd = new Label(composite, SWT.NONE);
		lblGtd.setText("GTD\u5173\u8054\u53F7");
		lblGtd.setBounds(321, 65, 84, 12);
		
		text_gtd = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
		text_gtd.setBounds(411, 59, 177, 18);

		TabItem tbtmBasicInfo = new TabItem(tabFolder, SWT.NONE);
		tbtmBasicInfo.setText("Extra Info");
		m_bindingContext = initDataBindings();

	}

	@Override
	public void setFocus() {
		// Set the focus
	}

	@Override
	public void doSave(IProgressMonitor monitor) {
		// Do the Save operation
	}

	@Override
	public void doSaveAs() {
		// Do the Save As operation
	}

	@Override
	public void init(IEditorSite site, IEditorInput input)
			throws PartInitException {
		this.setSite(site);
		this.setInput(input);
		this._viewSp = ((SpDetailEditorInput) input).getViewSp();
		System.out.println(_viewSp.getDealTicketNo());

	}

	@Override
	public boolean isDirty() {
		return false;
	}

	@Override
	public boolean isSaveAsAllowed() {
		return false;
	}
	protected DataBindingContext initDataBindings() {
		DataBindingContext bindingContext = new DataBindingContext();
		//
		IObservableValue observeTextText_dealTicketNoObserveWidget = WidgetProperties.text(SWT.Modify).observe(text_dealTicketNo);
		IObservableValue dealTicketNo_viewSpObserveValue = BeanProperties.value("dealTicketNo").observe(_viewSp);
		bindingContext.bindValue(observeTextText_dealTicketNoObserveWidget, dealTicketNo_viewSpObserveValue, null, null);
		//
		IObservableValue observeTextText_cnyAmountObserveWidget = WidgetProperties.text(SWT.Modify).observe(text_cnyAmount);
		IObservableValue cnyAmount_viewSpObserveValue = BeanProperties.value("cnyAmount").observe(_viewSp);
		bindingContext.bindValue(observeTextText_cnyAmountObserveWidget, cnyAmount_viewSpObserveValue, null, null);
		//
		IObservableValue observeTextText_branchNoObserveWidget = WidgetProperties.text(SWT.Modify).observe(text_branchNo);
		IObservableValue branchNo_viewSpObserveValue = BeanProperties.value("branchNo").observe(_viewSp);
		bindingContext.bindValue(observeTextText_branchNoObserveWidget, branchNo_viewSpObserveValue, null, null);
		//
		IObservableValue observeTextText_gtdNoObserveWidget = WidgetProperties.text(SWT.Modify).observe(text_gtdNo);
		IObservableValue gtdNo_viewSpObserveValue = BeanProperties.value("gtdNo").observe(_viewSp);
		bindingContext.bindValue(observeTextText_gtdNoObserveWidget, gtdNo_viewSpObserveValue, null, null);
		//
		IObservableValue observeTextText_productNameObserveWidget = WidgetProperties.text(SWT.Modify).observe(text_productName);
		IObservableValue productName_viewSpObserveValue = BeanProperties.value("productName").observe(_viewSp);
		bindingContext.bindValue(observeTextText_productNameObserveWidget, productName_viewSpObserveValue, null, null);
		//
		IObservableValue observeTextText_productCodeObserveWidget = WidgetProperties.text(SWT.Modify).observe(text_productCode);
		IObservableValue productCode_viewSpObserveValue = BeanProperties.value("productCode").observe(_viewSp);
		bindingContext.bindValue(observeTextText_productCodeObserveWidget, productCode_viewSpObserveValue, null, null);
		//
		IObservableValue observeTextText_ccyObserveWidget = WidgetProperties.text(SWT.Modify).observe(text_ccy);
		IObservableValue ccy_viewSpObserveValue = BeanProperties.value("ccy").observe(_viewSp);
		bindingContext.bindValue(observeTextText_ccyObserveWidget, ccy_viewSpObserveValue, null, null);
		//
		IObservableValue observeTextText_nominalPrinAcObserveWidget = WidgetProperties.text(SWT.Modify).observe(text_nominalPrinAc);
		IObservableValue nomialPrinAc_viewSpObserveValue = BeanProperties.value("nomialPrinAc").observe(_viewSp);
		bindingContext.bindValue(observeTextText_nominalPrinAcObserveWidget, nomialPrinAc_viewSpObserveValue, null, null);
		//
		IObservableValue observeTextText_acTypeObserveWidget = WidgetProperties.text(SWT.Modify).observe(text_acType);
		IObservableValue acType_viewSpObserveValue = BeanProperties.value("acType").observe(_viewSp);
		bindingContext.bindValue(observeTextText_acTypeObserveWidget, acType_viewSpObserveValue, null, null);
		//
		IObservableValue observeTextText_counterPartyNameObserveWidget = WidgetProperties.text(SWT.Modify).observe(text_counterPartyName);
		IObservableValue counterPartyName_viewSpObserveValue = BeanProperties.value("counterPartyName").observe(_viewSp);
		bindingContext.bindValue(observeTextText_counterPartyNameObserveWidget, counterPartyName_viewSpObserveValue, null, null);
		//
		IObservableValue observeTextText_counterPartyTypeObserveWidget = WidgetProperties.text(SWT.Modify).observe(text_counterPartyType);
		IObservableValue counterPartyType_viewSpObserveValue = BeanProperties.value("counterPartyType").observe(_viewSp);
		bindingContext.bindValue(observeTextText_counterPartyTypeObserveWidget, counterPartyType_viewSpObserveValue, null, null);
		//
		IObservableValue observeTextText_counterPartyCodeObserveWidget = WidgetProperties.text(SWT.Modify).observe(text_counterPartyCode);
		IObservableValue counterPartyCode_viewSpObserveValue = BeanProperties.value("counterPartyCode").observe(_viewSp);
		bindingContext.bindValue(observeTextText_counterPartyCodeObserveWidget, counterPartyCode_viewSpObserveValue, null, null);
		//
		IObservableValue observeTextText_opTypeObserveWidget = WidgetProperties.text(SWT.Modify).observe(text_opType);
		IObservableValue operationType_viewSpObserveValue = BeanProperties.value("operationType").observe(_viewSp);
		bindingContext.bindValue(observeTextText_opTypeObserveWidget, operationType_viewSpObserveValue, null, null);
		//
		IObservableValue observeTextText_agTypeObserveWidget = WidgetProperties.text(SWT.Modify).observe(text_agType);
		IObservableValue agreementType_viewSpObserveValue = BeanProperties.value("agreementType").observe(_viewSp);
		bindingContext.bindValue(observeTextText_agTypeObserveWidget, agreementType_viewSpObserveValue, null, null);
		//
		IObservableValue observeTextText_typeObserveWidget = WidgetProperties.text(SWT.Modify).observe(text_type);
		IObservableValue txnType_viewSpObserveValue = BeanProperties.value("txnType").observe(_viewSp);
		bindingContext.bindValue(observeTextText_typeObserveWidget, txnType_viewSpObserveValue, null, null);
		//
		IObservableValue observeSelectionDateTime_beginDateObserveWidget = WidgetProperties.selection().observe(dateTime_beginDate);
		IObservableValue beginDate_viewSpObserveValue = BeanProperties.value("beginDate").observe(_viewSp);
		bindingContext.bindValue(observeSelectionDateTime_beginDateObserveWidget, beginDate_viewSpObserveValue, null, null);
		//
		IObservableValue observeSelectionDateTime_endDateObserveWidget = WidgetProperties.selection().observe(dateTime_endDate);
		IObservableValue endDate_viewSpObserveValue = BeanProperties.value("endDate").observe(_viewSp);
		bindingContext.bindValue(observeSelectionDateTime_endDateObserveWidget, endDate_viewSpObserveValue, null, null);
		//
		IObservableValue observeTextText_statusObserveWidget = WidgetProperties.text(SWT.Modify).observe(text_status);
		IObservableValue status_viewSpObserveValue = BeanProperties.value("status").observe(_viewSp);
		bindingContext.bindValue(observeTextText_statusObserveWidget, status_viewSpObserveValue, null, null);
		//
		IObservableValue observeTextText_1ObserveWidget = WidgetProperties.text(SWT.Modify).observe(text_1);
		IObservableValue version_viewSpObserveValue = BeanProperties.value("version").observe(_viewSp);
		bindingContext.bindValue(observeTextText_1ObserveWidget, version_viewSpObserveValue, null, null);
		//
		IObservableValue observeTextText_2ObserveWidget = WidgetProperties.text(SWT.Modify).observe(text_2);
		IObservableValue subVersion_viewSpObserveValue = BeanProperties.value("subVersion").observe(_viewSp);
		bindingContext.bindValue(observeTextText_2ObserveWidget, subVersion_viewSpObserveValue, null, null);
		//
		IObservableValue observeTextText_gtdObserveWidget = WidgetProperties.text(SWT.Modify).observe(text_gtd);
		bindingContext.bindValue(observeTextText_gtdObserveWidget, gtdNo_viewSpObserveValue, null, null);
		//
		return bindingContext;
	}
}
